package com.hxci.zc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hxci.zc.domain.Dept;
import com.hxci.zc.mapper.DeptMapper;
import com.hxci.zc.service.DeptService;
import com.hxci.zc.util.PageUtils;
import com.hxci.zc.util.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxci.zc.domain.User;
import com.hxci.zc.mapper.UserMapper;
import com.hxci.zc.service.UserService;
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{
    @Autowired
    DeptMapper deptMapper;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String)params.get("name");
       /* params.put("limit","8");*/
        //方法一：没有写sql 语句基础上做分页
//        IPage<User> page = this.page(new Query<User>().getPage(params),new QueryWrapper<User>().like(StringUtils.isNotBlank(name),"name", name));
//        List<User> list = page.getRecords();
//        for (User user: list) {
//            Dept dept = deptMapper.selectById(user.getBid());
//            user.setBname(dept.getDname());
//        }
        //方法二：通过sql语句完成分页查询
        IPage<User> page = new Query<User>().getPage(params);
        List<User> list =this.baseMapper.query(page,name);
        page.setRecords(list);

        return new PageUtils(page);
    }
}
